OpenBuildings GenerativeComponents Help

Conditional Statements

Conditional modeling is an intermediate step between regular geometric modeling and scripting. It allows conditional statements to be used as an input property with two possible outcome. The conditional statement evaluates the current state of the model before deciding which of the two input options to implement.

In a parametric environment like OpenBuildings™ GenerativeComponents, the inputs to an technique that originally resulted in the successful creation of a node may not produce a node under another condition. As other nodes change the inputs of the node at hand may also be affected through its input dependencies. For instance, an intersection between two lines may succeed initially with both lines intersecting. However, after one of the lines has been moved there may be no more intersection. OpenBuildings™ GenerativeComponents anticipates this situation as a frequent possibility within parametric design explorations. If a technique fails to create a node successfully, an output Boolean property called Success takes on the value of false.

A successful intersection creates a point, in this case point05.

Once the intersection is not successful, the icon for the point05 node in the Graph fails, indicating that the node was not successfully created, and its Success property takes the value of false.

Using this Boolean property as an indicator for future nodes, we can make use of a principle called conditional statements. A conditional is a test case that decides which option to execute based on the value of a test value. In this case, our test value is the Success property of the intersection point: point05. 

First we create two additional points, one to serve as the constant start point of our test line, and the other, point05, as the alternate point in case our intersection point fails to compute.

If the intersection is successful we get the following result. 

If the intersection creating point05 fails, both the line and point are not created and their icons in the Graph fails.

We can recover from this fallback provided by OpenBuildings™ GenerativeComponents and use the conditional case mentioned above. The Success property is a variable of type Boolean, which means it has one of two values: true or false. Therefore, you can use this property to monitor the state of the nodes that are to be used in further operations in order to prevent errors further down the line. Such a test could be in the simplest case an inline conditional expression, which is a minimal form of script-like syntax embedded within an input field of a technique.

(Conditional Boolean Statement)?(Execute if Statement is true):(Execute if Statement if False)

For our example it would look like the line below:

EndPoint = point05.Success?point05:point07

If we use this expression for the end point of a third line, that line will be drawn either to the successful intersection point (in this case point05), or if the intersection fails, to another unrelated point (in this case point07). Point05.Success? tests the Success property and returns either point05, the first value after the "?" if the property is true, or point07 if it is false.

When the intersection point05 fails, the line is drawn to the backup point, point07, as specified in the conditional expression.

This is a powerful tool in OpenBuildings™ GenerativeComponents. It can be extended beyond the successful creation of a point. For example, a statement could be used to calculate the area of a BSplineSurface before placing a point at a specific UV parameter on the surface.

U = (10 < bsplineSurface01.Area < 20)?.25:.75
V = (10 < bsplineSurface01.Area < 20)?.75:.25

Similarly, a conditional statement can be used to evaluate the planarity of a polygon and visualize whether each polygon is in or out of plane in the View window. In the example below, the following code was written to control the color of the polygon array:

node polygon01 Bentley.GC.Polygon 
}
	Color       = polygon01.OutOfPlane
> 0.2 ? Colors.Green : Colors.Red; 
{